/*
 * StateTable.h
 *
 * Stores all states and transitions of the state machine
 * and controls the state machine itself
 *
 * Author: Zachary Masiello
 * Author: Peter-John Rowe
 */

#ifndef STATETABLE_H_
#define STATETABLE_H_

#include "IState.h"
#include "Transition.h"
#include "IEvent.h"
#include <pthread.h>
#include <map>
#include <vector>
#include <queue>
#include <iostream.h>

using namespace std;

// Typedefs
typedef vector<Transition*> StateTransitions;
typedef map<IState*,StateTransitions> StateTableMatrix;

class StateTable {
private:
	// Current state
	IState* currentState;
	// Boolean to run activity
	bool runActivity;
	// State Table Matrix
	StateTableMatrix matrix;
	// State Table Iterator
	StateTableMatrix::const_iterator matrixIterator;
	// Special run activity boolean for speed mode
	bool speedRunActivity;
	// Special run activity boolean for distance mode
	bool distRunActivity;
	// Special run activity boolean for time mode
	bool timeRunActivity;
	// Thread for accepted state
	pthread_t stateThread;
public:
	// Constructor
	StateTable();
	// Destructor
	virtual ~StateTable();
	// Assign state
	void assignState(IState* newState);
	// Assign Transition
	void assignTransition(IState* state,Transition* transition);
	// Set current state
	void setCurrentState(IState* state);
	// Set initial state
	void setDefaultInitialState(IState* state);
	// Accept event
	void accept(IEvent* event);
	// Gets current state
	IState* getCurrentState();
	// Gets the run activity boolean based on the state
	bool getRunActivity(IState* state);
	// Sets the run activity pertaining to the state
	void setRunActivity(IState* state,bool run);
};

#endif /* STATETABLE_H_ */
